﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEECommonTools;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class PlotPileTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";
        static double A3Height = 297 - 10 - Extensions.bottomHeight;
        static double intervalHeight = 26;//小于块高度设置高度
        static double tbH = 0;

        static double lastMegerHeight = 0;

        public static List<Tuple<string, int>> tuLst = new List<Tuple<string, int>>();

        #region 桩基
        /// <summary>
        /// 桩基
        /// </summary>
        /// <param name="db"></param>
        /// <param name="eType"></param>
        /// <param name="listRebar"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="eConType"></param>
        /// <param name="conValue"></param>
        /// <param name="scale"></param>
        public static void DrawingPileTable(Database db, MemberBase ret,  string dwgPath,
            string typeName, double pileL, double dowel, double dia, FDEE.Model.eConcreteClass eConType,
           out List<Tuple<string, int>> _tuLst, int pageNo = 0, int divNo = 0, int scale = 1, string tkPath = "")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("表格数据为空");
            }
            _dwgPath = dwgPath;


            //Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale - 297 * pageNo);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            //CalcPage(ret.RebarList, scale, ref divDic);
            //不需要分页
            divDic.Add(ret.RebarList);
            #endregion

            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                Extents2d ext = new Extents2d(M1, M1);
                lasTb = DrawPileTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2 + 1,
                    Extensions.curFont, scale, divDic[i], typeName, pileL, dowel,dia,  i);

                //Common.CreateLayoutNew(db, "桩基钢筋", ext, extMerge, scale,1, pageNo, divNo,false, tkPath);

                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(lasTb.Width + 10 * scale);
                    Extents2d extMerge = new Extents2d(pt.Convert2D(), pt.Convert2D());
                    Table tb = DrawMergeTable(db, ret,  ref extMerge, pt, mergeList,
                        Extensions.curFont, scale);
                  
                    Common.CreateLayoutL2R(db, "桩基钢筋", ext, extMerge, scale, 2, pageNo, divNo, false, tkPath);
                }
            }
            #endregion

            _tuLst = tuLst;
        }

        /// <summary>
        /// 桩基表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="rowNum"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbValue"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static Table DrawPileTable(Database db, ref Extents2d ext, Point3d startPoint,
            int rowNum, string txtStyle, double scale, RebarCollection tbValue, string typeName,
            double pileL, double dowel, double dia, int pageCount = 0)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("No.");
            headName.Add("No.");
            headName.Add("Dim.\\P(mm)");
            headName.Add("Sharp");
            headName.Add("Length\\P(mm)");
            headName.Add("Qty.");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");

            tbH = 0;


            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format(@"QUANTITIES FOR ONE " + pileL + "m-LONG Φ "+ dia + "m PILE - " + typeName + "(DOWEL=" + (dowel * 0.001).ToString("0.000") + "M)");
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.ScaleFactors = new Scale3d(1);
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                tb.Rows[0].Height = 7 * scale;

                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                tb.Rows[1].Height = 15 * scale;
                #endregion

                #region
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 12 * 3 * scale;
                    else if (i > colNum - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else
                        tb.Columns[i].Width = 7 * 3 * scale;
                }
                //行高
                //for (int i = 2; i < rowNum; ++i)
                //{
                //    tb.Rows[i].Height = 10 * scale;                    
                //}
                #endregion
                double totalW = 0;
                int numM = 0;
                #region 设置表格值
                if (tbValue.Count > 0)
                {

                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            // no rebars
                            string value = "";
                            tb.Cells[m + 2, 0].TextString = "Rebars"; //获取i行j列数据
                            tb.Cells[m + 2, 0].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, 0].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, 0].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, 0].Contents[0].TextStyleId = id;
                            tb.MergeCells(CellRange.Create(tb, 2, 0, tbValue.Count + 1, 0));
                            // no.
                            value = "";                  
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, 1].TextString = value;
                            tb.Cells[m + 2, 1].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, 1].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, 1].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, 1].Contents[0].TextStyleId = id;

                            // dia
                            tb.Cells[m + 2, 2].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, 2].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, 2].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, 2].Contents[0].TextStyleId = id;

                            //sharp
                            tb.Cells[m + 2, 3].TextString = tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, 3].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, 3].Alignment = CellAlignment.MiddleRight;
                            tb.Cells[m + 2, 3].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, 3].Contents[0].TextStyleId = id;

                            //length
                            tb.Cells[m + 2, 4].TextString = tbValue[m].Length.ToString("0.000");
                            tb.Cells[m + 2, 4].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, 4].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, 4].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, 4].Contents[0].TextStyleId = id;

                            //Quantity
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, 5].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, 5].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, 5].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, 5].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, 5].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, 6].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, 6].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, 6].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, 6].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, 6].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString().Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, 7].TextString = double.Parse(value).ToString("0.000") /*string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, 7].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, 7].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, 7].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, 7].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString().Trim();
                            totalW += tbValue[m].TotalWeight;
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, 8].TextString = double.Parse(value).ToString("0.000")/* string.Format("{0:N3}", double.Parse(value))*/;
                                tb.Cells[m + 2, 8].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, 8].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, 8].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, 8].Contents[0].TextStyleId = id;
                            }
                            if (tbValue[m].ShapeConfg.ToString().Contains("PileBT"))
                                _blcName = "PileBT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileT"))
                                _blcName = "PileT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileB"))
                                _blcName = "PileB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileMZBTB"))
                                _blcName = "PileMZBTB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileMZTB"))
                                _blcName = "PileMZTB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileMZBTM"))
                                _blcName = "PileMZBTM";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileMZBT"))
                                _blcName = "PileMZBT";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileMZB"))
                                _blcName = "PileMZB";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("PileC"))
                                _blcName = "PileC";
                            else if (tbValue[m].ShapeConfg.ToString().Contains("Pile"))
                                _blcName = "Pile";
                            db.CopyBlockFromFile(_dwgPath, _blcName);
                            if (tbValue[m].Formula.Replace("\\P", "|").Split('|').Length > 2)
                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 5 * 3 * scale + 2 * 3 * scale, -(7 * scale + 15 * scale + 10 * m + 2.5 * numM + 6.25)), 0.8, _blcName, _dwgPath, 0);
                            else
                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 5 * 3 * scale + 2 * 3 * scale, -(7 * scale + 15 * scale + 10 * m + 2.5 * numM + 5)), 0.8, _blcName, _dwgPath, 0);
                        }
                        catch (Exception ex)
                        { }
                        if (tbValue[m].Formula.Replace("\\P", "|").Split('|').Length > 2)
                        {
                            tb.Rows[m + 2].Height = 12.5 * scale;
                            numM++;
                        }
                        else
                        {
                            tb.Rows[m + 2].Height = 10 * scale;
                        }
                    }
                }

                #endregion

                tb.Cells[rowNum - 1, 0].TextString = "Summary";
                tb.Cells[rowNum - 1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum - 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rowNum - 1, 0].Contents[0].Rotation = 0;
                tb.Cells[rowNum - 1, 0].Contents[0].TextStyleId = id;
                tb.Rows[rowNum - 1].Height = 7 * scale;
                tb.MergeCells(CellRange.Create(tb, rowNum - 1, 0, rowNum - 1, colNum - 2));

                tb.Cells[rowNum - 1, colNum - 1].TextString = totalW.ToString("0.000");
                tb.Cells[rowNum - 1, colNum - 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[rowNum - 1, colNum - 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[rowNum - 1, colNum - 1].Contents[0].Rotation = 0;
                tb.Cells[rowNum - 1, colNum - 1].Contents[0].TextStyleId = id;

                #region 表格添加数据

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }

        /// <summary>
        /// 绘制合并项表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="headName"></param>
        /// <param name="listRebar"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        public static Table DrawMergeTable(Database db, MemberBase ret, ref Extents2d ext,
            Point3d startPoint, List<string> headName, string txtStyle, double scale)
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                Table tb = new Table();

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                #endregion

                #region 设置表格长宽
                bool isLoadOther = false;
                int row = dic.Count + 3;
                int col = 5;
                if (ret.UAN1N2 != 0)
                    row++;
                if (ret.UAN2N3 != 0)
                    row++;
                if (ret.UAN3N3 != 0)
                    row++;
                if (ret.UBN1N7 != 0)
                    row++;
                if (ret.UBN2N7 != 0)
                    row++;
                if (ret.UBN3N7 != 0)
                    row++;
                //row = dic.Count + 9;
                isLoadOther = true;

                tb.SetSize(row, col);
                tb.Position = startPoint;
                tb.GenerateLayout();
                #endregion

                #region 设置表头
                for (int i = 0; i < col; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i];
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                }
                #endregion

                #region 设置表格值
                // 第一行第一列
                tb.Cells[1, 0].TextString = "Bars";
                tb.Cells[1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;

                // 第一列最后一行
                tb.Cells[dic.Count + 1, 0].TextString = "Concrete";
                tb.Cells[dic.Count + 1, 0].Contents[0].TextHeight = 2 * scale;
                tb.Cells[dic.Count + 1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[dic.Count + 1, 0].Contents[0].Rotation = 0;
                tb.Cells[dic.Count + 1, 0].Contents[0].TextStyleId = id;

                // 其他数据
                #region Bars, Concreate数据
                double totalWeight = 0;
                for (int i = 1; i < row; ++i)
                {
                    if (i == dic.Count + 1)
                    {
                        tb.Cells[i, 1].TextString = string.Format("f'c={0}MPa", ret.ConcreteClass.ToString().Replace("C", ""));
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        tb.Cells[i, 2].TextString = "m3";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        tb.Cells[i, 3].TextString = ret.ConcreteVolumn.ToString("0.000")/*string.Format("{0:N3}", ret.ConcreteVolumn)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        KeyValuePair<eDB, List<RebarBase>> pr = new KeyValuePair<eDB, List<RebarBase>>();
                        if (dic.Count > i - 1)
                        {
                            pr = dic.ElementAt(i - 1);
                        }
                        if (pr.Value == null)
                        {
                            continue;
                        }

                        // 类型
                        tb.Cells[i, 1].TextString = pr.Key.ToString();
                        tb.Cells[i, 1].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 1].Contents[0].Rotation = 0;
                        tb.Cells[i, 1].Contents[0].TextStyleId = id;

                        // 单位
                        tb.Cells[i, 2].TextString = "kg";
                        tb.Cells[i, 2].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 2].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 2].Contents[0].Rotation = 0;
                        tb.Cells[i, 2].Contents[0].TextStyleId = id;

                        // 数量
                        double weight = 0;
                        foreach (RebarBase info in pr.Value)
                        {
                            weight += info.TotalWeight;
                        }

                        tb.Cells[i, 3].TextString = weight.ToString("0.000")/* string.Format("{0:N3}", weight)*/;
                        tb.Cells[i, 3].Contents[0].TextHeight = 2 * scale;
                        tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[i, 3].Contents[0].Rotation = 0;
                        tb.Cells[i, 3].Contents[0].TextStyleId = id;

                        // 总数
                        totalWeight += weight;
                    }

                    // 总数
                    tb.Cells[1, 4].TextString = totalWeight.ToString("0.000")/*string.Format("{0:N3}", totalWeight)*/;
                    tb.Cells[1, 4].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, 4].Contents[0].Rotation = 0;
                    tb.Cells[1, 4].Contents[0].TextStyleId = id;
                }
                #endregion

                #region other数据
                if (isLoadOther)
                {
                    tuLst = new List<Tuple<string, int>>();
                    int num = dic.Count + 2;
                    string uName = nameof(ret.UAN1N2);
                    if (ret.UAN1N2 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UAN1N2, num, scale);
                        num++;
                    }

                    uName = nameof(ret.UAN2N3);
                    if (ret.UAN2N3 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UAN2N3, num, scale);
                        num++;
                    }

                    uName = nameof(ret.UAN3N3);
                    if (ret.UAN3N3 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UAN3N3, num, scale);
                        num++;
                    }

                    uName = nameof(ret.UBN1N7);
                    if (ret.UBN1N7 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UBN1N7, num, scale);
                        num++;
                    }

                    uName = nameof(ret.UBN2N7);
                    if (ret.UBN2N7 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UBN2N7, num, scale);
                        num++;
                    }

                    uName = nameof(ret.UBN3N7);
                    if (ret.UBN3N7 != 0)
                    {
                        LoadOtherTableData(tb, ret, id, uName, ret.UBN3N7, num, scale);
                        num++;
                    }

                    tb.Cells[row - 1, 1].TextString = "Cover block";
                    tb.Cells[row - 1, 1].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[row - 1, 1].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[row - 1, 1].Contents[0].Rotation = 0;
                    tb.Cells[row - 1, 1].Contents[0].TextStyleId = id;

                    tb.Cells[row - 1, 2].TextString = "Number";
                    tb.Cells[row - 1, 2].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[row - 1, 2].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[row - 1, 2].Contents[0].Rotation = 0;
                    tb.Cells[row - 1, 2].Contents[0].TextStyleId = id;

                    tb.Cells[row - 1, 3].TextString = ret.numCB.ToString();
                    tb.Cells[row - 1, 3].Contents[0].TextHeight = 2 * scale;
                    tb.Cells[row - 1, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[row - 1, 3].Contents[0].Rotation = 0;
                    tb.Cells[row - 1, 3].Contents[0].TextStyleId = id;
                }
                #endregion

                #endregion

                #region 设置行高、列宽
                for (int i = 0; i < col; ++i)
                {
                    if (i == 0)
                    {
                        tb.Columns[i].Width = 20 * scale;
                    }
                    else if (i == 1)
                    {
                        tb.Columns[i].Width = 30 * scale;
                    }
                    else if (i == 2)
                    {
                        tb.Columns[i].Width = 20 * scale;
                    }
                    else if (i == 3)
                    {
                        tb.Columns[i].Width = 25 * scale;
                    }
                    else if (i == 4)
                    {
                        tb.Columns[i].Width = 25 * scale;
                    }
                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 8 * scale;
                }
                #endregion

                #region 合并单元格
                List<CellRange> cellList = new List<CellRange>();

                CellRange range1 = CellRange.Create(tb, 1, 0, dic.Count, 0);
                cellList.Add(range1);

                CellRange range2 = CellRange.Create(tb, 1, 2, dic.Count, 2);
                cellList.Add(range2);

                CellRange range3 = CellRange.Create(tb, 1, 4, dic.Count, 4);
                cellList.Add(range3);

                CellRange range4 = CellRange.Create(tb, dic.Count + 1, 3, dic.Count + 1, 4);
                cellList.Add(range4);

                CellRange range5 = CellRange.Create(tb, 0, 0, 0, 1);
                cellList.Add(range5);

                if (isLoadOther)
                {
                    CellRange range6 = CellRange.Create(tb, dic.Count + 2, 0, tb.Rows.Count - 1, 0);
                    cellList.Add(range6);
                    CellRange range7 = CellRange.Create(tb, dic.Count + 2, 2, tb.Rows.Count - 1, 2);
                    cellList.Add(range7);
                    for (int rm = dic.Count + 2; rm < row; rm++)
                    {
                        CellRange range = CellRange.Create(tb, rm, 3, rm, 4);
                        cellList.Add(range);
                    }
                }

                foreach (CellRange range in cellList)
                {
                    tb.MergeCells(range);
                }
                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                return tb;
            }
        }

        /// <summary>
        ///  墩柱合并U-bolt处理
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="ret"></param>
        /// <param name="id"></param>
        /// <param name="uBolt"></param>
        /// <param name="num"></param>
        /// <param name="rowNumIndex"></param>
        /// <param name="scale"></param>
        public static void LoadOtherTableData(Table tb, MemberBase ret, ObjectId id, string uBolt, int num, int rowNumIndex, double scale)
        {
            if (tb == null)
            {
                throw new Exception("表格异常");
            }

            // 第一列
            tb.Cells[rowNumIndex, 0].TextString = "Others";
            tb.Cells[rowNumIndex, 0].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 0].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 0].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 0].Contents[0].TextStyleId = id;

            // 第一列
            string Name = "";
            string sBegin = "";
            string sEnd = "";
            int beginIndex = 0;
            int endIndex = 0;
            beginIndex = int.Parse(uBolt.Substring(3, 1));
            endIndex = int.Parse(uBolt.Substring(5, 1));
            if (uBolt.ToLower().Contains("a"))
            {
                Name = "M10/U-Bolt A";

                RebarBase beginItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "a" && x.MBarMark == beginIndex) || (x.CBarMark.ToLower() == "" && x.MBarMark == beginIndex));
                RebarBase endItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "a" && x.MBarMark == endIndex) || (x.CBarMark.ToLower() == "" && x.MBarMark == endIndex));
                sBegin = beginItem.Diameter.ToString().Substring(2, 2);
                sEnd = endItem.Diameter.ToString().Substring(2, 2);
            }
            else if (uBolt.ToLower().Contains("b"))
            {
                Name = "M10/U-Bolt B";
                RebarBase beginItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "b" && x.MBarMark == beginIndex) || (x.CBarMark.ToLower() == "" && x.MBarMark == beginIndex));
                RebarBase endItem = ret.RebarList.Find(x => (x.CBarMark.ToLower() == "b" && x.MBarMark == endIndex) || (x.CBarMark.ToLower() == "" && x.MBarMark == endIndex));
                sBegin = beginItem.Diameter.ToString().Substring(2, 2);
                sEnd = endItem.Diameter.ToString().Substring(2, 2);
            }

            Name = string.Format("{0}({1}/{2})", Name, sBegin, sEnd);
            tb.Cells[rowNumIndex, 1].TextString = Name;
            tb.Cells[rowNumIndex, 1].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 1].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 1].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 1].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 2].TextString = "number";
            tb.Cells[rowNumIndex, 2].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 2].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 2].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 2].Contents[0].TextStyleId = id;

            tb.Cells[rowNumIndex, 3].TextString = num.ToString();
            tb.Cells[rowNumIndex, 3].Contents[0].TextHeight = 2 * scale;
            tb.Cells[rowNumIndex, 3].Alignment = CellAlignment.MiddleCenter;
            tb.Cells[rowNumIndex, 3].Contents[0].Rotation = 0;
            tb.Cells[rowNumIndex, 3].Contents[0].TextStyleId = id;

            Tuple<string, int> tu = new Tuple<string, int>(Name, num);
            tuLst.Add(tu);
        }

        #endregion

        #region 桩基合并
        /// <summary>
        /// 批量墩柱数量比较多合并绘制
        /// </summary>
        /// <param name="db"></param>
        /// <param name="rets"></param>
        /// <param name="pierHeight"></param>
        /// <param name="startPoint"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="type"></param>
        /// <param name="title"></param>
        /// <param name="num"></param>
        public static void DrawPileListMergeTB(Database db,
Point3d startPoint, string txtStyle, double scale, List<Tuple<MemberBase, List<Tuple<string, int>>, PilePara, int>> tuLst, string pier = "", string title = "MAINLINE", int pageNo = 0, int divNo = 0, string tkPath = "")
        {

            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());

            DrawPListMergeTable(db, tuLst, ref ext, startPoint.Convert3D(),
                                    Extensions.curFont, scale, pier,  title);


            string note = @"Notes:
1.LD in this drawing is dowel length.";
           
            TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(1,-1-ext.L()), note, 1, 3, 200, true);
            Common.CreateLayoutNew(db, "桩基钢筋", ext, scale, 1, pageNo, divNo);

        }

        public static void DrawPListMergeTable(Database db, List<Tuple<MemberBase, List<Tuple<string, int>>, PilePara, int>> tuLst, ref Extents2d ext,
Point3d startPoint, string txtStyle, double scale, string pier = "", string title = "MAINLINE")
        {

            Table tb = new Table();
            List<Dictionary<eDB, List<RebarBase>>> dicList = new List<Dictionary<eDB, List<RebarBase>>>();
            int totalNum = 0;
            foreach (var tu in tuLst)
            {
                totalNum += tu.Item4;
            }
            foreach (var tu in tuLst)
            {
                MemberBase ret = tu.Item1;
                if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                {
                    throw new Exception("数据异常");
                }

                Dictionary<eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                #region 统计合并数据
                foreach (RebarBase item in ret.RebarList)
                {
                    if (dic.Count == 0)
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                    else
                    {
                        List<RebarBase> items = new List<RebarBase>();
                        dic.TryGetValue(item.Diameter, out items);
                        if (items == null || items.Count == 0)
                        {
                            items = new List<RebarBase>();
                        }
                        items.Add(item);
                        dic[item.Diameter] = items;
                    }
                }
                dicList.Add(dic);


                #endregion

            }


            //#region 设置表格长宽

            int row = 1 + 5 + 1 + 6 + 1 + 15+1;

            int col = 6 + tuLst.Count;

            tb.SetSize(row, col);
            tb.Position = startPoint;
            tb.GenerateLayout();
            //#endregion

            #region 设置表头
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                tb.Cells[0, 0].TextString = String.Format("PILE LIST AND QUANTITIES FOR {0} OF " + title + "({1} PILES)",
                      pier, totalNum);

                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;

                tb.Cells[1, 0].TextString = "Items";
                tb.Cells[1, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 0].Contents[0].Rotation = 0;
                tb.Cells[1, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 0, 5, 2));

                tb.Cells[1, 3].TextString = "unit";
                tb.Cells[1, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 3].Contents[0].Rotation = 0;
                tb.Cells[1, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 3, 5, 3));

                tb.Cells[1, 4].TextString = "Pile";
                tb.Cells[1, 4].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4].Contents[0].Rotation = 0;
                tb.Cells[1, 4].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4, 1, 4 + tuLst.Count - 1));

                for (int i = 0; i < tuLst.Count; i++)
                {
                    tb.Cells[2, 4 + i].TextString = "Dia.=" + tuLst[i].Item3.pileDia.ToString("0.00") + "m";
                    tb.Cells[2, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[2, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[2, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[2, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[3, 4 + i].TextString = tuLst[i].Item3.type;
                    tb.Cells[3, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[3, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[3, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[3, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[4, 4 + i].TextString = "Length=" + tuLst[i].Item3.pileLength.ToString("0.00") + "m";
                    tb.Cells[4, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[4, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[4, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[4, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[5, 4 + i].TextString = "LD=" + (tuLst[i].Item3.DOWEL*0.001).ToString("0.00") + "m";
                    tb.Cells[5, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[5, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[5, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[5, 4 + i].Contents[0].TextStyleId = id;
                }





                tb.Cells[6, 0].TextString = "Pile Qty.";
                tb.Cells[6, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 0].Contents[0].Rotation = 0;
                tb.Cells[6, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 6, 0, 6, 2));

                tb.Cells[6, 3].TextString = "Number";
                tb.Cells[6, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 3].Contents[0].Rotation = 0;
                tb.Cells[6, 3].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 5, 3, 5, 3));

                for (int i = 0; i < tuLst.Count; i++)
                {
                    tb.Cells[6, 4 + i].TextString = tuLst[i].Item4.ToString();
                    tb.Cells[6, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[6, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[6, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[6, 4 + i].Contents[0].TextStyleId = id;
                }



                tb.Cells[7, 0].TextString = "Material";
                tb.Cells[7, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 0].Contents[0].Rotation = 0;
                tb.Cells[7, 0].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 7, 0, row - 1, 0));

                tb.Cells[7, 1].TextString = "Bars";
                tb.Cells[7, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 1].Contents[0].Rotation = 0;
                tb.Cells[7, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 7, 1, 12, 1));



                tb.Cells[7, 2].TextString = "DB32";
                tb.Cells[7, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 2].Contents[0].Rotation = 0;
                tb.Cells[7, 2].Contents[0].TextStyleId = id;

                tb.Cells[8, 2].TextString = "DB28";
                tb.Cells[8, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[8, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[8, 2].Contents[0].Rotation = 0;
                tb.Cells[8, 2].Contents[0].TextStyleId = id;

                tb.Cells[9, 2].TextString = "DB25";
                tb.Cells[9, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[9, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[9, 2].Contents[0].Rotation = 0;
                tb.Cells[9, 2].Contents[0].TextStyleId = id;


                tb.Cells[10, 2].TextString = "DB20";
                tb.Cells[10, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[10, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[10, 2].Contents[0].Rotation = 0;
                tb.Cells[10, 2].Contents[0].TextStyleId = id;

                tb.Cells[11, 2].TextString = "DB16";
                tb.Cells[11, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[11, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[11, 2].Contents[0].Rotation = 0;
                tb.Cells[11, 2].Contents[0].TextStyleId = id;

                tb.Cells[12, 2].TextString = "DB12";
                tb.Cells[12, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[12, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[12, 2].Contents[0].Rotation = 0;
                tb.Cells[12, 2].Contents[0].TextStyleId = id;
               

                tb.Cells[7, 3].TextString = "kg";
                tb.Cells[7, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 3].Contents[0].Rotation = 0;
                tb.Cells[7, 3].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 7, 3, 12, 3));

                tb.Cells[13, 1].TextString = "Concrete (f'c = 30 MPa)";
                tb.Cells[13, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[13, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[13, 1].Contents[0].Rotation = 0;
                tb.Cells[13, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 13, 1, 13, 2));

                tb.Cells[13, 3].TextString = "m3";
                tb.Cells[13, 3].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[13, 3].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[13, 3].Contents[0].Rotation = 0;
                tb.Cells[13, 3].Contents[0].TextStyleId = id;
              


                tb.Cells[14, 1].TextString = "Other";
                tb.Cells[14, 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[14, 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[14, 1].Contents[0].Rotation = 0;
                tb.Cells[14, 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 14, 1, row - 1, 1));

                //tb.Cells[14, 3].TextString = "number";
                //tb.Cells[14, 3].Contents[0].TextHeight = 2.5 * scale;
                //tb.Cells[14, 3].Alignment = CellAlignment.MiddleCenter;
                //tb.Cells[14, 3].Contents[0].Rotation = 0;
                //tb.Cells[14, 3].Contents[0].TextStyleId = id;
                //tb.MergeCells(CellRange.Create(tb, 14, 3, 27, 3));
                for (int i = 14; i < row; i++)
                {
                    tb.Cells[i, 3].TextString = "number";
                    tb.Cells[i, 3].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[i, 3].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[i, 3].Contents[0].Rotation = 0;
                    tb.Cells[i, 3].Contents[0].TextStyleId = id;
                }
     

                tb.Cells[14, 2].TextString = "M10/U-Bolt A(32/25)";
                tb.Cells[14, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[14, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[14, 2].Contents[0].Rotation = 0;
                tb.Cells[14, 2].Contents[0].TextStyleId = id;

                tb.Cells[15, 2].TextString = "M10/U-Bolt A(28/25)";
                tb.Cells[15, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[15, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[15, 2].Contents[0].Rotation = 0;
                tb.Cells[15, 2].Contents[0].TextStyleId = id;

                tb.Cells[16, 2].TextString = "M10/U-Bolt A(28/25)";
                tb.Cells[16, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[16, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[16, 2].Contents[0].Rotation = 0;
                tb.Cells[16, 2].Contents[0].TextStyleId = id;

                tb.Cells[17, 2].TextString = "M10/U-Bolt A(25/20)";
                tb.Cells[17, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[17, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[17, 2].Contents[0].Rotation = 0;
                tb.Cells[17, 2].Contents[0].TextStyleId = id;

                tb.Cells[18, 2].TextString = "M10/U-Bolt A(20/20)";
                tb.Cells[18, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[18, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[18, 2].Contents[0].Rotation = 0;
                tb.Cells[18, 2].Contents[0].TextStyleId = id;

                tb.Cells[19, 2].TextString = "M10/U-Bolt A(20/16)";
                tb.Cells[19, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[19, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[19, 2].Contents[0].Rotation = 0;
                tb.Cells[19, 2].Contents[0].TextStyleId = id;

                tb.Cells[20, 2].TextString = "M10/U-Bolt A(16/16)";
                tb.Cells[20, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[20, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[20, 2].Contents[0].Rotation = 0;
                tb.Cells[20, 2].Contents[0].TextStyleId = id;

                tb.Cells[21, 2].TextString = "M10/U-Bolt B(32/25)";
                tb.Cells[21, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[21, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[21, 2].Contents[0].Rotation = 0;
                tb.Cells[21, 2].Contents[0].TextStyleId = id;

                tb.Cells[22, 2].TextString = "M10/U-Bolt B(25/25)";
                tb.Cells[22, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[22, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[22, 2].Contents[0].Rotation = 0;
                tb.Cells[22, 2].Contents[0].TextStyleId = id;


                tb.Cells[23, 2].TextString = "M10/U-Bolt B(28/20)";
                tb.Cells[23, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[23, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[23, 2].Contents[0].Rotation = 0;
                tb.Cells[23, 2].Contents[0].TextStyleId = id;

                tb.Cells[24, 2].TextString = "M10/U-Bolt B(25/20)";
                tb.Cells[24, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[24, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[24, 2].Contents[0].Rotation = 0;
                tb.Cells[24, 2].Contents[0].TextStyleId = id;

                tb.Cells[25, 2].TextString = "M10/U-Bolt B(20/20)";
                tb.Cells[25, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[25, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[25, 2].Contents[0].Rotation = 0;
                tb.Cells[25, 2].Contents[0].TextStyleId = id;

                tb.Cells[26, 2].TextString = "M10/U-Bolt B(25/16)";
                tb.Cells[26, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[26, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[26, 2].Contents[0].Rotation = 0;
                tb.Cells[26, 2].Contents[0].TextStyleId = id;

                tb.Cells[27, 2].TextString = "M10/U-Bolt B(20/16)";
                tb.Cells[27, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[27, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[27, 2].Contents[0].Rotation = 0;
                tb.Cells[27, 2].Contents[0].TextStyleId = id;

                tb.Cells[28, 2].TextString = "M10/U-Bolt B(16/16)";
                tb.Cells[28, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[28, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[28, 2].Contents[0].Rotation = 0;
                tb.Cells[28, 2].Contents[0].TextStyleId = id;

                tb.Cells[29, 2].TextString = "Cover block";
                tb.Cells[29, 2].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[29, 2].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[29, 2].Contents[0].Rotation = 0;
                tb.Cells[29, 2].Contents[0].TextStyleId = id;

                double total3225UA = 0;
                double total2825UA = 0;
                double total2525UA = 0;
                double total2520UA = 0;
                double total2020UA = 0;
                double total2016UA = 0;
                double total1616UA = 0;
                double total3225UB = 0;
                double total2525UB = 0;
                double total2820UB = 0;
                double total2520UB = 0;
                double total2020UB = 0;
                double total2516UB = 0;
                double total2016UB = 0;
                double total1616UB = 0;

                for (int i = 0; i < tuLst.Count; i++)
                {

                    tb.Cells[13, 4 + i].TextString = ((double.Parse(tuLst[i].Item1.ConcreteVolumn.ToString("0.000")))* tuLst[i].Item4).ToString(); ;
                    tb.Cells[13, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[13, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[13, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[13, 4 + i].Contents[0].TextStyleId = id;

                    tb.Cells[29, 4 + i].TextString =( tuLst[i].Item1.numCB *tuLst[i].Item4).ToString(); ;
                    tb.Cells[29, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[29, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[29, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[29, 4 + i].Contents[0].TextStyleId = id;

                    double weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB32])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[7, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[7, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[7, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[7, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[7, 4 + i].Contents[0].TextStyleId = id;

                    //total12weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB28])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[8, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[8, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[8, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[8, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[8, 4 + i].Contents[0].TextStyleId = id;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB25])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[9, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[9, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[9, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[9, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[9, 4 + i].Contents[0].TextStyleId = id;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB20])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[10, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[10, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[10, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[10, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[10, 4 + i].Contents[0].TextStyleId = id;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB16])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[11, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[11, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[11, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[11, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[11, 4 + i].Contents[0].TextStyleId = id;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB12])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    tb.Cells[12, 4 + i].TextString = weight.ToString("0.000"); ;
                    tb.Cells[12, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[12, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[12, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[12, 4 + i].Contents[0].TextStyleId = id;

                    int ucount = 0;
                    Tuple<string, int> uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(32/25)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total3225UA += ucount;
                    }

                    tb.Cells[14, 4 + i].TextString = ucount.ToString();
                    tb.Cells[14, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[14, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[14, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[14, 4 + i].Contents[0].TextStyleId = id;


                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(28/25)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2825UA += ucount;
                    }
                    tb.Cells[15,4 + i].TextString = ucount.ToString();
                    tb.Cells[15,4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[15,4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[15,4 + i].Contents[0].Rotation = 0;
                    tb.Cells[15,4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(25/25)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2525UA += ucount;
                    }
                    tb.Cells[16, 4 + i].TextString = ucount.ToString();
                    tb.Cells[16, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[16, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[16, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[16, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(25/20)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2520UA += ucount;
                    }
                    tb.Cells[17,4 + i].TextString = ucount.ToString();
                    tb.Cells[17,4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[17,4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[17,4 + i].Contents[0].Rotation = 0;
                    tb.Cells[17,4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(20/20)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2020UA += ucount;
                    }
                    tb.Cells[18,4 + i].TextString = ucount.ToString();
                    tb.Cells[18,4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[18,4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[18,4 + i].Contents[0].Rotation = 0;
                    tb.Cells[18,4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(20/16)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2016UA += ucount;
                    }
                    tb.Cells[19, 4 + i].TextString = ucount.ToString();
                    tb.Cells[19, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[19, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[19, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[19, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt A(16/16)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total1616UA += ucount;
                    }
                    tb.Cells[20, 4 + i].TextString = ucount.ToString();
                    tb.Cells[20, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[20, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[20, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[20, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(32/25)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total3225UB += ucount;
                    }
                    tb.Cells[21, 4 + i].TextString = ucount.ToString();
                    tb.Cells[21, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[21, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[21, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[21, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(25/25)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2525UB += ucount;
                    }
                    tb.Cells[22, 4 + i].TextString = ucount.ToString(); 
                    tb.Cells[22, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[22, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[22, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[22, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(28/20)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2820UB += ucount;
                    }
                    tb.Cells[23, 4 + i].TextString = ucount.ToString();
                    tb.Cells[23, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[23, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[23, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[23, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(25/20)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2520UB += ucount;
                    }
                    tb.Cells[24, 4 + i].TextString = ucount.ToString();
                    tb.Cells[24, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[24, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[24, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[24, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(20/20)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2020UB += ucount;
                    }
                    tb.Cells[25, 4 + i].TextString = ucount.ToString();
                    tb.Cells[25, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[25, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[25, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[25, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(25/16)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2516UB += ucount;
                    }
                    tb.Cells[26, 4 + i].TextString = ucount.ToString();
                    tb.Cells[26, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[26, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[26, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[26, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(20/16)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total2016UB += ucount;
                    }
                    tb.Cells[27, 4 + i].TextString = ucount.ToString();
                    tb.Cells[27, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[27, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[27, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[27, 4 + i].Contents[0].TextStyleId = id;

                    ucount = 0;
                    uItem = tuLst[i].Item2.Find(t => t.Item1 == "M10/U-Bolt B(16/16)");
                    if (uItem != null)
                    {
                        ucount = uItem.Item2 * tuLst[i].Item4;
                        total1616UB += ucount;
                    }
                    tb.Cells[28, 4 + i].TextString = ucount.ToString();
                    tb.Cells[28, 4 + i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[28, 4 + i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[28, 4 + i].Contents[0].Rotation = 0;
                    tb.Cells[28, 4 + i].Contents[0].TextStyleId = id;
                }


                double total32weight = 0;
                double total28weight = 0;
                double total25weight = 0;
                double total20weight = 0;
                double total16weight = 0;
                double total12weight = 0;
                double totalVolumn = 0;
                double totalCover = 0;
                dicList = new List<Dictionary<eDB, List<RebarBase>>>();

                foreach (var tu in tuLst)
                {
                    MemberBase ret = tu.Item1;
                    if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
                    {
                        throw new Exception("数据异常");
                    }
                    totalVolumn += double.Parse(ret.ConcreteVolumn.ToString("0.000")) * tu.Item4;
                    totalCover += ret.numCB * tu.Item4;
                    Dictionary <eDB, List<RebarBase>> dic = new Dictionary<eDB, List<RebarBase>>();      // 统计合并项

                    #region 统计合并数据
                    foreach (RebarBase item in ret.RebarList)
                    {
                        if (dic.Count == 0)
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                        else
                        {
                            List<RebarBase> items = new List<RebarBase>();
                            dic.TryGetValue(item.Diameter, out items);
                            if (items == null || items.Count == 0)
                            {
                                items = new List<RebarBase>();
                            }
                            items.Add(item);
                            dic[item.Diameter] = items;
                        }
                    }
                    dicList.Add(dic);
                    #endregion

                }
                for (int i = 0; i < tuLst.Count; i++)
                {
                    double weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB32])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total32weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB28])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total28weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB25])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total25weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB20])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total20weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB16])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total16weight += weight;

                    weight = 0;
                    try
                    {
                        foreach (RebarBase info in dicList[i][eDB.DB12])
                        {
                            weight += info.TotalWeight;
                        }
                    }
                    catch { }
                    weight = weight * tuLst[i].Item4;
                    total12weight += weight;

                }
                tb.Cells[1, 4 + tuLst.Count].TextString = "Total";
                tb.Cells[1, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[1, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[1, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[1, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 1, 4 + tuLst.Count, 5, 4 + tuLst.Count + 1));

                tb.Cells[6, 4 + tuLst.Count].TextString = (totalNum).ToString();
                tb.Cells[6, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[6, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[6, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[6, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 6, 4 + tuLst.Count, 6, 4 + tuLst.Count + 1));



                tb.Cells[7, 4 + tuLst.Count].TextString = total32weight.ToString("0.000");
                tb.Cells[7, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[7, 4 + tuLst.Count].Contents[0].TextStyleId = id;

                tb.Cells[8, 4 + tuLst.Count].TextString = total28weight.ToString("0.000");
                tb.Cells[8, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[8, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[8, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[8, 4 + tuLst.Count].Contents[0].TextStyleId = id;

                tb.Cells[9, 4 + tuLst.Count].TextString = total25weight.ToString("0.000");
                tb.Cells[9, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[9, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[9, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[9, 4 + tuLst.Count].Contents[0].TextStyleId = id;


                tb.Cells[10, 4 + tuLst.Count].TextString = total20weight.ToString("0.000");
                tb.Cells[10, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[10, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[10, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[10, 4 + tuLst.Count].Contents[0].TextStyleId = id;

                tb.Cells[11, 4 + tuLst.Count].TextString = total16weight.ToString("0.000");
                tb.Cells[11, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[11, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[11, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[11, 4 + tuLst.Count].Contents[0].TextStyleId = id;

                tb.Cells[12, 4 + tuLst.Count].TextString = total12weight.ToString("0.000");
                tb.Cells[12, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[12, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[12, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[12, 4 + tuLst.Count].Contents[0].TextStyleId = id;

                tb.Cells[7, 4 + tuLst.Count + 1].TextString = (total12weight + total16weight + total20weight + total25weight + total28weight + total32weight).ToString();
                tb.Cells[7, 4 + tuLst.Count + 1].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[7, 4 + tuLst.Count + 1].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[7, 4 + tuLst.Count + 1].Contents[0].Rotation = 0;
                tb.Cells[7, 4 + tuLst.Count + 1].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 7, 4 + tuLst.Count + 1, 12, 4 + tuLst.Count + 1));

                tb.Cells[13, 4 + tuLst.Count].TextString = totalVolumn.ToString();
                tb.Cells[13, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[13, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[13, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[13, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 13, 4 + tuLst.Count, 13, 4 + tuLst.Count + 1));

                tb.Cells[14, 4 + tuLst.Count].TextString = total3225UA.ToString();
                tb.Cells[14, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[14, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[14, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[14, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 14, 4 + tuLst.Count, 14, 4 + tuLst.Count + 1));

                tb.Cells[15, 4 + tuLst.Count].TextString = total2825UA.ToString(); 
                tb.Cells[15, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[15, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[15, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[15, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 15, 4 + tuLst.Count, 15, 4 + tuLst.Count + 1));

                tb.Cells[16, 4 + tuLst.Count].TextString = total2525UA.ToString();
                tb.Cells[16, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[16, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[16, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[16, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 16, 4 + tuLst.Count, 16, 4 + tuLst.Count + 1));

                tb.Cells[17, 4 + tuLst.Count].TextString = total2520UA.ToString(); 
                tb.Cells[17, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[17, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[17, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[17, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 17, 4 + tuLst.Count, 17, 4 + tuLst.Count + 1));

                tb.Cells[18, 4 + tuLst.Count].TextString = total2020UA.ToString() ;
                tb.Cells[18, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[18, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[18, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[18, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 18, 4 + tuLst.Count, 18, 4 + tuLst.Count + 1));

                tb.Cells[19, 4 + tuLst.Count].TextString = total2016UA.ToString();
                tb.Cells[19, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[19, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[19, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[19, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 19, 4 + tuLst.Count, 19, 4 + tuLst.Count + 1));

                tb.Cells[20, 4 + tuLst.Count].TextString = total1616UA.ToString();
                tb.Cells[20, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[20, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[20, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[20, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 20, 4 + tuLst.Count, 20, 4 + tuLst.Count + 1));

                tb.Cells[21, 4 + tuLst.Count].TextString = total3225UB.ToString();
                tb.Cells[21, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[21, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[21, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[21, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 21, 4 + tuLst.Count, 21, 4 + tuLst.Count + 1));

                tb.Cells[22, 4 + tuLst.Count].TextString = total2525UB.ToString();
                tb.Cells[22, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[22, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[22, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[22, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 22, 4 + tuLst.Count, 22, 4 + tuLst.Count + 1));


                tb.Cells[23, 4 + tuLst.Count].TextString = total2820UB.ToString();
                tb.Cells[23, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[23, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[23, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[23, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 23, 4 + tuLst.Count, 23, 4 + tuLst.Count + 1));

                tb.Cells[24, 4 + tuLst.Count].TextString = total2520UB.ToString();
                tb.Cells[24, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[24, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[24, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[24, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 24, 4 + tuLst.Count, 24, 4 + tuLst.Count + 1));

                tb.Cells[25, 4 + tuLst.Count].TextString = total2020UB.ToString(); 
                tb.Cells[25, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[25, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[25, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[25, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 25, 4 + tuLst.Count, 25, 4 + tuLst.Count + 1));

                tb.Cells[26, 4 + tuLst.Count].TextString = total2516UB.ToString(); 
                tb.Cells[26, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[26, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[26, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[26, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 26, 4 + tuLst.Count, 26, 4 + tuLst.Count + 1));

                tb.Cells[27, 4 + tuLst.Count].TextString = total2016UB.ToString();
                tb.Cells[27, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[27, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[27, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[27, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 27, 4 + tuLst.Count, 27, 4 + tuLst.Count + 1));

                tb.Cells[28, 4 + tuLst.Count].TextString = total1616UB.ToString(); 
                tb.Cells[28, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[28, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[28, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[28, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 28, 4 + tuLst.Count, 28, 4 + tuLst.Count + 1));

                tb.Cells[29, 4 + tuLst.Count].TextString = totalCover.ToString();
                tb.Cells[29, 4 + tuLst.Count].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[29, 4 + tuLst.Count].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[29, 4 + tuLst.Count].Contents[0].Rotation = 0;
                tb.Cells[29, 4 + tuLst.Count].Contents[0].TextStyleId = id;
                tb.MergeCells(CellRange.Create(tb, 29, 4 + tuLst.Count, 29, 4 + tuLst.Count + 1));

                for (int i = 0; i < col; ++i)
                {
                    if (i ==2)
                        tb.Columns[i].Width = 35 * scale;
                    else if (i > 2 && i < col - 2)
                        tb.Columns[i].Width = 25 * scale;
                    else
                        tb.Columns[i].Width = 18 * scale;

                }

                for (int i = 0; i < row; ++i)
                {
                    tb.Rows[i].Height = 7 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                tr.Commit();
                Extents3d ex3d = new Extents3d(tb.Bounds.Value.MinPoint.Convert3D(), tb.Bounds.Value.MaxPoint.Convert3D());
                ext = ex3d.Convert2D();
                #endregion


                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

            }


        }



        #endregion

        #region 目录页绘制
        public static void DrawPileCatalogue(Database db,
Point3d startPoint, string txtStyle, double scale, List<Tuple<int, string, string, int, int>> tuList,  int pageNo = 0, int divNo = 0, string tkPath = "")
        {

            Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
            DrawPCatalogue(db, tuList, ref ext, startPoint.Convert3D(),Extensions.curFont, scale);
            Common.CreateLayoutNew(db, "桩基钢筋", ext, scale, 1, pageNo, divNo);
        }

        public static void DrawPCatalogue(Database db, List<Tuple<int, string, string, int, int>> tuList, ref Extents2d ext,
 Point3d startPoint, string txtStyle, double scale)
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("SN");
            headName.Add("Drawing Title");
            headName.Add("Drawing No.");
            headName.Add("Pages");
            headName.Add("Page No.");
            for (int cn = 0; cn < 2; cn++)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                        OpenMode.ForWrite) as BlockTableRecord;

                    ObjectId id;
                    TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                    id = st[txtStyle];
                    int rowNum = 28;
                    // 创建table 
                    if (cn == 1)
                        startPoint = startPoint.Convert3D(185);
                    else
                        startPoint = startPoint.Convert3D();
                    Table tb = new Table();
                    int colNum = headName.Count;
                    tb.SetSize(rowNum, colNum);       // 设置几行几列

                        tb.Position = startPoint;
                    tb.GenerateLayout();

                    #region 第一行 标题


                    for (int i = 0; i < colNum; ++i)
                    {
                        tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                        tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[0, i].Contents[0].Rotation = 0;
                        tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[0, i].Contents[0].TextStyleId = id;
                    }
                    //tb.Rows[0].Height = 10 * scale;
                    #endregion

                    #region
                    // 设置列宽
                    for (int i = 0; i < colNum; ++i)
                    {
                        if (i == 0)
                            tb.Columns[i].Width = 12 * scale;
                        else if (i == 1)
                            tb.Columns[i].Width = 90 * scale;
                        else if (i == 2)
                            tb.Columns[i].Width = 40 * scale;
                        else if (i == 3)
                            tb.Columns[i].Width = 18 * scale;
                        else
                            tb.Columns[i].Width = 22 * scale;

                    }
                    for (int i = 0; i < rowNum; ++i)
                    {
                        tb.Rows[i].Height = 8 * scale;

                    }

                    #endregion

                    #region 设置表格值
                    if (tuList.Count > 0)
                    {

                        for (int m = 0; m < rowNum-1; m++)
                        {
                            try
                            {
                                if (cn == 0)
                                {
                                    if (m < tuList.Count)
                                    {
                                        tb.Cells[m + 1, 0].TextString = tuList[m].Item1.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 0].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 0].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 0].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 0].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 1].TextString = tuList[m].Item2.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 1].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 1].Alignment = CellAlignment.MiddleLeft;
                                        tb.Cells[m + 1, 1].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 1].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 2].TextString = tuList[m].Item3.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 2].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 2].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 2].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 2].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 3].TextString = tuList[m].Item4.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 3].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 3].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 3].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 3].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 4].TextString = tuList[m].Item5.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 4].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 4].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 4].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 4].Contents[0].TextStyleId = id;
                                    }
                                    else
                                    {
                                        tb.Cells[m + 1, 0].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 0].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 0].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 0].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 0].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 1].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 1].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 1].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 1].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 1].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 2].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 2].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 2].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 2].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 2].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 3].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 3].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 3].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 3].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 3].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 4].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 4].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 4].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 4].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 4].Contents[0].TextStyleId = id;
                                    }
                                }
                                else
                                {
                                    if (m + rowNum-1 < tuList.Count)
                                    {
                                        tb.Cells[m + 1, 0].TextString = tuList[m +(rowNum-1)].Item1.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 0].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 0].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 0].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 0].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 1].TextString = tuList[m + (rowNum - 1)].Item2.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 1].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 1].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 1].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 1].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 2].TextString = tuList[m + (rowNum - 1)].Item3.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 2].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 2].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 2].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 2].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 3].TextString = tuList[m + (rowNum - 1)].Item4.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 3].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 3].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 3].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 3].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 4].TextString = tuList[m + (rowNum - 1)].Item5.ToString(); //获取i行j列数据
                                        tb.Cells[m + 1, 4].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 4].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 4].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 4].Contents[0].TextStyleId = id;
                                    }
                                    else
                                    {
                                        tb.Cells[m + 1, 0].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 0].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 0].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 0].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 0].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 1].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 1].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 1].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 1].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 1].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 2].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 2].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 2].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 2].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 2].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 3].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 3].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 3].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 3].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 3].Contents[0].TextStyleId = id;

                                        tb.Cells[m + 1, 4].TextString = " "; //获取i行j列数据
                                        tb.Cells[m + 1, 4].Contents[0].TextHeight = 2 * scale;
                                        tb.Cells[m + 1, 4].Alignment = CellAlignment.MiddleCenter;
                                        tb.Cells[m + 1, 4].Borders.Horizontal.Margin = 1 * scale;
                                        tb.Cells[m + 1, 4].Contents[0].TextStyleId = id;
                                    }
                                }
                            }
                            catch (Exception ex)
                            { }

                        }
                    }

                    #endregion



                    tb.Layer = "细线";
                    tb.LineWeight = LineWeight.LineWeight013;
                    tb.ColorIndex = 4;
                    modelSpace.AppendEntity(tb);
                    tr.AddNewlyCreatedDBObject(tb, true);
                    ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                    #region  边框粗线设置
                    List<Point2d> pList = new List<Point2d>();
                    Point2d pt1 = startPoint.Convert2D();
                    pList.Add(pt1);
                    Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                    pList.Add(pt2);
                    Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                    pList.Add(pt3);
                    Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                    pList.Add(pt4);
                    PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                    #endregion


                    tr.Commit();

                }
            }
        }
        #endregion


        #region 桩基平面坐标图
        public static void DrawPileCoordinates(Database db,
Point3d startPoint, string txtStyle, double scale, System.Data.DataTable dt, System.Data.DataTable dtP, out int pageCount,string title= "MAINLINE", int pageNo = 0, int divNo = 0,  string tkPath = "")
        {
            pageCount = 1;
            List<Tuple<int, List<Tuple<string, int>>>> pageLst = new List<Tuple<int, List<Tuple<string, int>>>>();

            CalCoorPage(dt, dtP,ref pageLst, Extensions.PileCoorRowCount);

            List<Point2d> ptLst = new List<Point2d>();
            
            pageCount = pageLst.Count;
            for (int i = 0; i < pageLst.Count; i++)
            {
                ptLst = new List<Point2d>();
                Extents2d ext = new Extents2d(startPoint.Convert2D(420*i), startPoint.Convert2D(420 * i));
                #region 表格绘制
                Table tb= DrawPCoordinates(db, dt, pageLst[i], ref ext, startPoint.Convert3D(420 * i), Extensions.curFont, scale,title);
                string titleText = "PILE COORDINATES";             
                //string str2 = "";
                TextPloter.PrintScaleDoubleSideText(db, startPoint.Convert2D(420 * i).Convert2D(tb.Width*0.5, 3.5 * scale), 3, titleText, "", ref ext, scale, Extensions.curFont);
                #endregion
                #region  Note
                string Note = @"Notes:
1.This drawing is to show the pile coordinates for "+ pageLst[i].Item2[0].Item1+ " to "+ pageLst[i].Item2[pageLst[i].Item2.Count-1].Item1 + " of  Mainline.\\P"+
@"2.Coordinates system: WGS - 84.
3.The pile rig auger mast shall always be positioned parallel to Railway track during pile bore.
4.The pile rig shall always be parked with the auger must facing parallel to railway track.
5.Pile reinforcement cage assembly shall be located at the outside of the work areas.
6.Excavated abandoned soil should be stock in the designate area and cleaned up in time to keep the site clean and tidy.
7.Sufficient precaution will have taken so that no settlement of railway track will occur.
8.Machineries used for construction will be kept at a safe distance from railway track.
9.No machineries or vehicle including hanging portion of crane etc.will cross the railway track without permission.
10.All truck mixers, mobile / crawler cranes, or truck mounted concrete pumps that are used for concrete work will be carefully operated and parked at agreed safe zones.
11.Safety barriers(or soft barricades) to be installed with warning signs and lights at the boundary of the safety zone along sides the railroads.
12.During working along sides of the railroads, flag men, watchmen and look -out shall be assigned for special safety precautions.
  ";
                Extents2d extN = new Extents2d(startPoint.Convert2D(420 * i + ext.W()+10), startPoint.Convert2D(420 * i + ext.W() + 10));
                TextPloter.PrintMultiText(db, ref extN, startPoint.Convert3D(420 * i+ext.W() + 10), Note, 1, 3, 200, true);
                #endregion

                #region 
                ptLst = new List<Point2d>();
                if (pageLst[i].Item2.Count > 1)
                    CalCoorMargin(dt, pageLst[i], out ptLst);
                else
                {
                    if (i > 0)
                        CalCoorMargin(dt, pageLst[i - 1], pageLst[i], out ptLst);
                    else
                        CalCoorMargin(dt,  pageLst[i], pageLst[i + 1], out ptLst);
                }
       

                #endregion
                Common.CreatePileCoorLayout(db, "桩基钢筋", ext, extN, ptLst, scale, 1, pageNo, i);

                Point2d ptTitle = Point2d.Origin.Convert2D(Extensions.leftWidth + (420 - 20 - 5) * 0.5,
                    297 - 18).Convert2D(420 * i, -297 * pageNo);
                string str1 = " LAYOUT PLAN OF PILE ";
                string str2 = "1:1000@A3";
                TextPloter.PrintScaleDoubleSideTextNew(db, ptTitle, 2 * 1.25, str1, str2, ref ext, 1, Extensions.curFont,false);
            }
        }
        public static Table DrawPCoordinates(Database db, System.Data.DataTable dt, Tuple<int, List<Tuple<string, int>>> pageInfo, ref Extents2d ext,
Point3d startPoint, string txtStyle, double scale,string title= "MAINLINE")
        {
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Location");
            headName.Add("Pier No.");
            headName.Add("Pile No.");
            headName.Add("Type");
            headName.Add("Dia.(m)");
            headName.Add("Length(m)");
            headName.Add("Coordinates(m)");
            headName.Add("Coordinates(m)");
            headName.Add("Cut off \\Plevel(MSL/m)");
            headName.Add("Dowel(m)");
            Table tb = new Table();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                int rowNum = 2+ pageInfo.Item1;
                startPoint = startPoint.Convert3D();
              
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列

                tb.Position = startPoint;
                tb.GenerateLayout();

                #region 第一行 标题

                
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[0, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[0, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[0, i].Contents[0].Rotation = 0;
                    tb.Cells[0, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[0, i].Contents[0].TextStyleId = id;
                    if (i == 6|| i == 7)
                    {
                        string val = "N";
                        if(i==7)
                            val = "E";
                        tb.Cells[1, i].TextString = val; //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, 0, 6, 0, 7));
                    }
                    else
                        tb.MergeCells(CellRange.Create(tb, 0, i, 1, i));
                }
              ;
                #endregion

                #region 列宽行高设置
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 6|| i == 7 || i == 8)
                        tb.Columns[i].Width = 20 * scale;                  
                    else
                        tb.Columns[i].Width = 16 * scale;

                }
                for (int i = 0; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6.35 * scale;

                }

                #endregion

                #region 设置表格值
                try
                {
                    int startNo = 2;
                    int MergeNo = 2;
                    tb.Cells[startNo, 0].TextString = title; //获取i行j列数据
                    tb.Cells[startNo, 0].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[startNo, 0].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[startNo, 0].Contents[0].Rotation = 0;
                    tb.Cells[startNo, 0].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[startNo, 0].Contents[0].TextStyleId = id;
                    tb.MergeCells(CellRange.Create(tb, startNo, 0, rowNum-1, 0));
                    foreach (var item in  pageInfo.Item2)
                    {
                        MergeNo = startNo + item.Item2;
                        System.Data.DataRow[] drs = dt.Select("PierNo='" + item.Item1 + "'");
                        tb.Cells[startNo, 1].TextString = item.Item1; //获取i行j列数据
                        tb.Cells[startNo, 1].Contents[0].TextHeight = 2.5 * scale;
                        tb.Cells[startNo, 1].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[startNo, 1].Contents[0].Rotation = 0;
                        tb.Cells[startNo, 1].Borders.Horizontal.Margin = 1 * scale;
                        tb.Cells[startNo, 1].Contents[0].TextStyleId = id;
                        tb.MergeCells(CellRange.Create(tb, startNo, 1, MergeNo - 1, 1));
                        for (int i = 0; i < drs.Length; i++)
                        {
       

                            tb.Cells[startNo, 2].TextString = drs[i]["PileNo"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 2].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 2].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 2].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 2].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 2].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 3].TextString = drs[i]["Type"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 3].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 3].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 3].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 3].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 3].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 4].TextString = drs[i]["Dia"].ToString();  //获取i行j列数据
                            tb.Cells[startNo, 4].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 4].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 4].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 4].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 4].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 5].TextString = drs[i]["Length"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 5].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 5].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 5].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 5].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 5].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 6].TextString = drs[i]["CoordN"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 6].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 6].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 6].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 6].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 6].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 7].TextString = drs[i]["CoordE"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 7].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 7].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 7].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 7].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 7].Contents[0].TextStyleId = id;
                  
                            tb.Cells[startNo, 8].TextString = drs[i]["Cut"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 8].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 8].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 8].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 8].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 8].Contents[0].TextStyleId = id;

                            tb.Cells[startNo, 9].TextString = drs[i]["Dowel"].ToString(); //获取i行j列数据
                            tb.Cells[startNo, 9].Contents[0].TextHeight = 2.5 * scale;
                            tb.Cells[startNo, 9].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[startNo, 9].Contents[0].Rotation = 0;
                            tb.Cells[startNo, 9].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[startNo, 9].Contents[0].TextStyleId = id;

                        
                            startNo++;
                        }

                    }

                }
                catch (Exception ex)
                { }




                #endregion



                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion


                tr.Commit();

            }
            return tb;
        }

        private static void CalCoorPage(System.Data.DataTable dt, System.Data.DataTable dtP, ref List<Tuple<int, List<Tuple<string, int>>>> tuL, int pageMaxRow = 30)
        {
            int page = 0;
            //List<Tuple<int, List<Tuple<string,int> >>> tuL = new List<Tuple<int,List<Tuple<string,int>>>>();
            tuL = new List<Tuple<int, List<Tuple<string, int>>>>();
            int pageRow = 0;
            List<Tuple<string, int>> tuPInfo = new List<Tuple<string, int>>();
            for (int i = 0; i < dtP.Rows.Count; i++)
            {

                System.Data.DataRow[] drs= dt.Select("PierNo='" + dtP.Rows[i]["PierNo"] + "'");
                Tuple<string, int> tu = new Tuple<string, int>(dtP.Rows[i]["PierNo"].ToString(), drs.Length);
                pageRow += drs.Length;                
                if(pageRow< pageMaxRow)
                {
                    tuPInfo.Add(tu);
                    if(i== dtP.Rows.Count-1)
                    {
                        Tuple<int, List<Tuple<string, int>>> tuP = new Tuple<int, List<Tuple<string, int>>>(pageRow, tuPInfo);
                        tuL.Add(tuP);
                    }
                }
                else
                {
                    pageRow -= drs.Length;
                    Tuple<int, List<Tuple<string, int>>> tuP = new Tuple<int, List<Tuple<string, int>>>(pageRow, tuPInfo);
                    tuL.Add(tuP);
                    pageRow = 0;
                    tuPInfo = new List<Tuple<string, int>>();
                    pageRow += drs.Length;
                    tuPInfo.Add(tu);
                    if (i == dtP.Rows.Count - 1)
                    {
                        tuP = new Tuple<int, List<Tuple<string, int>>>(pageRow, tuPInfo);
                        tuL.Add(tuP);
                    }
                }
            }

        }

        private static void CalCoorMargin(System.Data.DataTable dt, Tuple<int, List<Tuple<string, int>>> pageInfo,out List<Point2d> ptLst)
        {
            ptLst = new List<Point2d>();
            System.Data.DataRow[] drs = dt.Select("PierNo='" + pageInfo.Item2[0].Item1 + "'");
            Polyline pL = new Polyline() { };
            List<Point2d> ptPLLst = new List<Point2d>();
            Polyline pL0 = new Polyline() { };
            List<Point2d> ptPLLst0 = new List<Point2d>();
            Polyline pL1 = new Polyline() { };
            List<Point2d> ptPLLst1 = new List<Point2d>();
            Point2d pt0 = new Point2d();
            Point2d pt1 = new Point2d();
            for (int m=0;m<pageInfo.Item2.Count;m++)
            {
                Tuple<string, int> item = pageInfo.Item2[m];
                drs = dt.Select("PierNo='" + item.Item1 + "'");
                for (int i = 0; i < drs.Length; i++)
                {
                    Point2d pt = new Point2d(double.Parse(drs[i]["CoordE"].ToString()), double.Parse(drs[i]["CoordN"].ToString()));
                    pL.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                    ptPLLst.Add(pt);   
                    if(m==0)
                    {            
                        pL0.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                        ptPLLst0.Add(pt);
                    }
                    if (m == pageInfo.Item2.Count-1)
                    {
                        pL1.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                        ptPLLst1.Add(pt);
                    }
                }
            }

            Extents2d ext = new Extents2d(pL.Bounds.Value.MinPoint.Convert2D(), pL.Bounds.Value.MaxPoint.Convert2D());
            Extents2d ext0 = new Extents2d(pL0.Bounds.Value.MinPoint.Convert2D(), pL0.Bounds.Value.MaxPoint.Convert2D());
            Extents2d ext1 = new Extents2d(pL1.Bounds.Value.MinPoint.Convert2D(), pL1.Bounds.Value.MaxPoint.Convert2D());
            pt0 = ext0.GetCenter();
            pt1 = ext1.GetCenter();
            ptLst.Add(ext.MinPoint);       
            ptLst.Add(ext.MaxPoint);
            ptLst.Add(pt0);
            ptLst.Add(pt1);
        }

        private static void CalCoorMargin(System.Data.DataTable dt, Tuple<int, List<Tuple<string, int>>> pageInfo0, Tuple<int, List<Tuple<string, int>>> pageInfo, out List<Point2d> ptLst)
        {
            ptLst = new List<Point2d>();
            System.Data.DataRow[] drs = dt.Select("PierNo='" + pageInfo.Item2[0].Item1 + "'");
            Polyline pL = new Polyline() { };
            List<Point2d> ptPLLst = new List<Point2d>();
            Polyline pL0 = new Polyline() { };
            List<Point2d> ptPLLst0 = new List<Point2d>();
            Polyline pL1 = new Polyline() { };
            List<Point2d> ptPLLst1 = new List<Point2d>();
            Point2d pt0 = new Point2d();
            Point2d pt1 = new Point2d();

            Tuple<string, int> item = pageInfo0.Item2[pageInfo0.Item2.Count - 1];
            drs = dt.Select("PierNo='" + item.Item1 + "'");
            for (int i = 0; i < drs.Length; i++)
            {
                Point2d pt = new Point2d(double.Parse(drs[i]["CoordE"].ToString()), double.Parse(drs[i]["CoordN"].ToString()));
                pL.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                ptPLLst.Add(pt);

                pL0.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                ptPLLst0.Add(pt);

            }



            item = pageInfo.Item2[0];
            drs = dt.Select("PierNo='" + item.Item1 + "'");
            for (int i = 0; i < drs.Length; i++)
            {
                Point2d pt = new Point2d(double.Parse(drs[i]["CoordE"].ToString()), double.Parse(drs[i]["CoordN"].ToString()));
                pL.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                ptPLLst.Add(pt);

                pL1.AddVertexAt(0, pt.Convert2D(), 0, 0, 0);
                ptPLLst1.Add(pt);

            }


            Extents2d ext = new Extents2d(pL.Bounds.Value.MinPoint.Convert2D(), pL.Bounds.Value.MaxPoint.Convert2D());
            Extents2d ext0 = new Extents2d(pL0.Bounds.Value.MinPoint.Convert2D(), pL0.Bounds.Value.MaxPoint.Convert2D());
            Extents2d ext1 = new Extents2d(pL1.Bounds.Value.MinPoint.Convert2D(), pL1.Bounds.Value.MaxPoint.Convert2D());
            pt0 = ext0.GetCenter();
            pt1 = ext1.GetCenter();
            ptLst.Add(ext.MinPoint);
            ptLst.Add(ext.MaxPoint);
            ptLst.Add(pt0);
            ptLst.Add(pt1);
        }
        #endregion
    }

    public class PilePara
    {
        public string type { get; set; }                        // 构造物类型（字符串）
        public int eSubType { get; set; }                       // 构造物子类型
        public double pileLength { get; set; } //桩长
        public double pileDia { get; set; } //桩径
        public double DOWEL { get; set; }  //深入承台高度
    }
}
